from typing import Union
import numpy as np


class Individual:
    """Object storing a search point and its fitness value."""

    def __init__(self, x: np.ndarray, f: float) -> None:
        """Instantiation of self.x and self.f"""
        self.x = x
        self.f = f

    def __mul__(
        self,
        other: Union[int, float, np.ndarray, "Individual"]
    ) -> "Individual":
        """Multiply the value of self.x with the value for other."""
        if(type(other).__name__ in ['int', 'float']):
            self.x = self.x * other
            return

        if(type(other) == np.ndarray):
            self.x = np.multiply(self.x, other)
        else:
            self.x = np.multiply(self.x, other.x)

    def __lt__(self, other: "Individual") -> bool:  # less than
        """Return comparision of self.f"""
        if(self.f < other.f):
            return True
        else:
            return False

    def __repr__(self) -> str:
        """Representation of Individual object"""
        return str(self.x) + "with f: " + str(self.f)
